<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('颁发根证书')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-issueCa">
        	
        <div class="form-group" th:if="${issueCa!=null}">
        	<input type="hidden" name="parentId" th:value="${issueCa.id}">
            <label class="col-sm-3 control-label is-required">颁发者：</label>
            <div class="col-sm-6">
                <input id="issueName" name="issueName" class="form-control" type="text" th:value="${issueCa.certName}" disabled="disabled">
            </div>
        </div>
        <div class="form-group">	
            <label class="col-sm-3 control-label is-required">证书主题：</label>
            <div class="col-sm-6">
                <input id="subjectDn" name="subjectDn" class="form-control" type="text">
            </div>
        </div>
        
         <div class="form-group">
				<label class="col-sm-3 control-label is-required">证书年限：</label>
				<div class="col-sm-6">
					<div class="radio-box">
						<input type="radio" id="10" name="year" value="10">
						<label for="10">10年</label>
					</div>
					  <div class="radio-box">
						<input type="radio" id="20" name="year" value="20">
						<label for="20">20年</label>
					</div>
					 <div class="radio-box">
						<input type="radio" id="30" name="year" value="30">
						<label for="30">30年</label>
					</div>
					<div class="radio-box">
						<input type="radio" id="40" name="year" value="40">
						<label for="40">40年</label>
					</div>
						<div class="radio-box">
						<input type="radio" id="50" name="year" value="50">
						<label for="50">50年</label>
					</div>
				</div>
		</div>
        
        <div class="form-group"  th:if="${issueCa==null}">
				<label class="col-sm-3 control-label is-required">证书算法：</label>
				<div class="col-sm-6">
				    <div class="radio-box">
						<input type="radio" id="RSA" name="algorithm" value="RSA" checked="checked">
						<label for="RSA">RSA</label>
					</div>
				    <div class="radio-box">
						<input type="radio" id="SM2" name="algorithm" value="SM2">
						<label for="SM2">SM2</label>
					</div>
				</div>
				
		</div>
		
		  <div class="form-group keySize"  th:if="${(issueCa!=null && issueCa.algorithm == 'RSA') || (issueCa==null)}">
				<label class="col-sm-3 control-label is-required">密钥长度：</label>
				<div class="col-sm-6">
					
				    <div class="radio-box">
						<input type="radio" id="keySize" name="keySize" value="2048" checked="checked">
						<label for=keySize>2048位</label>
					</div>
				    <div class="radio-box">
						<input type="radio" id="keySize" name="keySize" value="4096">
						<label for="keySize">4096位</label>
					</div>
				</div>
				
		</div>
		

		
		<div class="form-group" th:if="${issueCa!=null}">
				<label class="col-sm-3 control-label  is-required">密钥增强用法：</label>
				<div class="col-sm-6">
				    <label class="check-box" th:each="enhanceUsage : ${enhanceUsageList}">
				        <input type="checkbox" th:value="${enhanceUsage.id}" id="enhanceUsage" name="enhanceUsage" th:text="${enhanceUsage.usageName}"></label>
			</div>
		</div>

        <div class="form-group">
                <label class="col-sm-3 control-label">证书颁发策略</label>
                <div class="col-sm-6">
                    <div class="input-daterange input-group">
                     <span class="input-group-addon">策略OID</span>
                        <input type="text" class="form-control" name="policyOids"/>
                       
                    </div>
                </div>
                <div class="col-sm-1">
                    <div>
                       	<a class="btn btn-primary btn-sm" id="addData"><i class="fa fa-plus"></i>添加</a>
                    </div>
                </div>
                
                
            </div>
		 <div id="addLine"></div>
		 <div class="form-group" >	
            <label class="col-sm-3 control-label is-required">OCSP查询地址：</label>
            <div class="col-sm-6">
                <input id="ocsp" name="ocsp" class="form-control" type="text" >
            </div>
        </div>
        
         <div class="form-group" >	
            <label class="col-sm-3 control-label is-required">CA Crt证书地址：</label>
            <div class="col-sm-6">
                <input id="crt" name="crt" class="form-control" type="text" >
            </div>
        </div>
        
         <div class="form-group" >	
            <label class="col-sm-3 control-label is-required">CRL吊销列表地址：</label>
            <div class="col-sm-6">
                <input id="crl" name="crl" class="form-control" type="text" >
            </div>
        </div>

    </form>
            <div class="box-footer" style="padding-top: 50px;">
				<div class="col-sm-offset-5 col-sm-6">
				    <button type="button" class="btn btn-sm btn-primary" onclick="submit()"><i class="fa fa-check"></i>确定</button>&nbsp;
				     <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
				</div>
          </div>
    </div>
    <th:block th:include="include :: footer" />
    <script type="text/javascript">
    	var prefix = ctx + "ca";
    	var parentId = $("input[name='parentId']").val(); 
	    
	    $("#subjectDn").click(function(){
	    	if($(this).val() == null || $(this).val() == ''){
	    		$.modal.open("构建证书主题", prefix + "/buildSubjectDn",600);
	    	}
			
	    })
	    
	     $("#addData").click(function () {
            var html =$('<div class="form-group"><label class="col-sm-3 control-label"></label><div class="col-sm-6"> <div class="input-daterange input-group"><span class="input-group-addon">策略OID</span>' +
                '  <input type="text" class="form-control" name="policyOids"/> ' +
               ' </div> </div></div>');
            var btnDel = $("<div class=\"col-sm-1\"><a href=\"javascript:;\" class=\"deleteLine\">删除</a></div>");
            btnDel.click(function() {
                html.remove();
            });
            html.append(btnDel);
            $("#addLine").append(html);

        })
        
	    $("input[name='algorithm']").change(function () {
	    	var val = $('input[name="algorithm"]:checked').val();
	        if (val === "SM2") {
	          $(".keySize").hide();
	        }else {
	          $(".keySize").show();
	        }
	    });
	    
	    function submit() {
	    	var subjectDn = $("#subjectDn").val();
	    	if(subjectDn == null || subjectDn == ''){
	    		$.modal.msgWarning('证书主题不能为空');
	    		return;
	    	}
	    	if(parentId == null || parentId == ''){
	    		var ocsp = $("#ocsp").val();
		    	if(ocsp == null || ocsp == ''){
		    		$.modal.msgWarning('OCSP查询地址不能为空');
		    		return;
		    	}
		    	var crl = $("#crl").val();
		    	if(crl == null || crl == ''){
		    		$.modal.msgWarning('CRL吊销列表地址不能为空');
		    		return;
		    	}
		    	
		    	var crt = $("#crt").val();
		    	if(crt == null || crt == ''){
		    		$.modal.msgWarning('CA Crt证书地址不能为空');
		    		return;
		    	}
	    	}
	    	$.operate.saveTab(prefix + "/issueRootCa", $('#form-issueCa').serialize());
	      
	    	
	    }

	    
    </script>
</body>
</html>
